﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LCL.CodeHelper
{
    /// <summary>
    /// 命名规则处理
    /// </summary>
    public class NameRule
    {
        private string _rule = "firstupper";
        private string _format = "uc_|lcl_|table|zt_|lmg|zte|cms_|tky_|base_|_|sys_";
        public NameRule(string rule,string format)
        {
            this._rule = !string.IsNullOrWhiteSpace(rule) ? rule : this._rule;
            this._format = !string.IsNullOrWhiteSpace(format) ? format : this._format;
        }
        public string GetClassName(string TabName)
        {
            if(string.IsNullOrWhiteSpace(TabName)) return "";
            string name = Configure(TabName, _format);
            return TabNameRuled(name);
        }
        
        private string Configure(string TabName, string format)
        {
            if (string.IsNullOrWhiteSpace(TabName)) return "";
            string[] arr = format.Split('|');
            for (int i = 0; i < arr.Length; i++)
            {
                TabName = TabName.Replace(arr[i], "");
            }
            return TabName;
        }
        private string TabNameRuled(string TabName)
        {
            if (string.IsNullOrWhiteSpace(TabName)) return "";
            string newTabName = TabName;
            switch (_rule.ToLower())
            {
                case "lower":
                    newTabName = TabName.ToLower();
                    break;
                case "upper":
                    newTabName = TabName.ToUpper();
                    break;
                case "firstupper":
                    {
                        string strfir = TabName.Substring(0, 1).ToUpper();
                        newTabName = strfir + TabName.Substring(1);
                    }
                    break;
                case "same":
                    break;
                default:
                    break;
            }
            return newTabName;
        }

        #region Create
        public static NameRule CreateFirstUpper(string format)
        {
            return new NameRule("firstupper", format);
        }
        public static NameRule CreateLower(string format)
        {
            return new NameRule("lower", format);
        }
        public static NameRule CreateUpperr(string format)
        {
            return new NameRule("upper", format);
        }
        public static NameRule CreateSame(string format)
        {
            return new NameRule("same", format);
        }
        #endregion
    }
}
